<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        html {
            /*第一种*/
            /*scroll-behavior: smooth;*/
        }
        body {
            position: relative;
        }
        .box1 {
            height: 800px;
            background: aqua;
        }
        .box1 {
            height: 800px;
            background: #3d4444;
        }
        .box3 {
            height: 800px;
            background: #96176e;
        }
        .box4 {
            height: 800px;
            background: #908aef;
        }

        .btn {
            position: fixed;
            left: 0;
            top: 100vh;
            transform: translateY(-110%);
        }
    </style>
</head>
<body>
<div class="box1"></div>
<div class="box2"></div>
<div class="box3"></div>
<div class="box4"></div>
<button id="btn" class="btn">回到顶部</button>

<script>
    const btn = document.querySelector("#btn")

    btn.onclick = () => {
        // window.scrollTo({
        //     top: 0
        // })
        window.scrollTo({
            top: 0,
            behavior: "smooth"
        })
    }
</script>
</body>
</html>